package timerwheel

import (
	"fmt"
	"reflect"
	"runtime"
)

// 定时任务类型
type TimerTaskType int64

const (
	TimerTask_one  TimerTaskType = 1 //一次任务
	TimerTask_loop TimerTaskType = 2 //循环任务
)

type taskModel struct {
	id          uint64               //定时任务唯一ID
	typ         TimerTaskType        //任务类型
	callback    func(...interface{}) //定时任务回调方法
	endCallback func()               //定时任务结束时的回调方法
	params      []interface{}        //定时任务回调参数
	tickTimer   int64                //运行时间
	loopTimer   int64                //循环步长
	timerKey    int64                //定时器中的key
	// timerBucketID        int                  //所属时间桶ID
	// timerWheelID         int                  //所属时间轮
	// surplusRoundTimes    int                  //剩余转动圈数
	// surplusRoundNum      int                  //剩余转动次数
	// loopTaskNeedRoundNum int  //循环任务能转动的圈数
	loopCount int  //循环任务剩余执行次数
	isDelete  bool //任务是否删除

	Next *taskModel
}

func (this *taskModel) init() {
	this.id = 0
	this.typ = 0
	this.callback = nil
	this.endCallback = nil
	this.params = nil
	this.tickTimer = 0
	this.loopTimer = 0
	this.timerKey = 0
	this.loopCount = 0
	this.isDelete = true
	this.Next = nil
}

func (this *taskModel) String() string {
	// if !this.isDelete {
	// 	this.callback(this.params...)
	// }
	pc := runtime.FuncForPC(reflect.ValueOf(this.callback).Pointer())
	// _, line := pc.FileLine(pc.Entry())
	return fmt.Sprintf("Function is defined in %s id:%d isdel:%v \n", pc.Name(), this.id, this.isDelete)
}
